<?php
/*
 * @Date: 2020-05-03 22:03:52
 * @名称: 上传控制器
 * @版本: 0.01
 * @作者: 初雪桜
 * @邮箱: 202184199@qq.com
 * @最后编辑人: 初雪桜
 * @LastEditTime: 2021-01-30 20:05:01
 * @FilePath: /Site/app/useradmin/controller/login.php
 */

namespace app\useradmin\controller;

use app\BaseController;
use app\useradmin\controller\User\Login\VerificationUser;
use CURLFile;
use sina\sina;
use think\facade\Db;
use think\facade\View;

class Login extends BaseController
{
    public function OpenView()
    {

        return View::fetch("", [
            "useradmin" => config("useradminConfig.useradmin_serverHost"),
        ]);
    }
    public function Login()
    {
        $username = input('username'); //@i 用户名
        $password = input('password'); //@k 密码
        $recaptchaToken =  input('post.g-recaptcha-response'); //@j 谷歌token
        $googlePrivateKey = config("useradminConfig.recaptcha_private_key");
        if ($username && $password && $recaptchaToken) { //@v 判断这三个必须有不能为空
            $url = "https://recaptcha.net/recaptcha/api/siteverify?secret={$googlePrivateKey}&response={$recaptchaToken}"; //@v 获取前台用户传入 recaptcha 的token 并且认证
            $html = json_decode(file_get_contents($url), true);
            if ($html['success']) { //@l 判断是否认证成功 
                //@b 执行登陆 
                $VerificationUser = new VerificationUser($this->app);
                return $VerificationUser->Run($username, $password);
            } else { //@w 认证失败
                return errorJsonReturn("User-10006");
            }
        } else {
            return errorJsonReturn("User-10005");
        }
    }
}
function asc2bin($temp)
{
    $len = strlen($temp);
    $data = '';
    for ($i = 0; $i < $len; $i++) {
        $data .= sprintf('%08b', ord(substr($temp, $i, 1)));
    }
    return $data;
}
